From 74c8d5716f385ab3637a8bcdd262dd2e1e524fcd Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 28 Jul 2014 19:35:08 -0700 Subject: [PATCH] Correctly preserve plugin deps When copying files over from the old root to the new root on a fresh compilation, care must be taken to preserve the correct plugin/host version of each dependency. The previous code copied back over at most one library, but this commit fixes this behavior by copying over all targets necessary for compilation. --- src/cargo/ops/cargo_rustc/context.rs | 14 ++++++++++++++ src/cargo/ops/cargo_rustc/fingerprint.rs | 20 +++++++++++++++----- tests/test_cargo_cross_compile.rs | 5 ++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 9f19fab97..ad078865b 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -233,4 +233,18 @@ impl PlatformRequirement { _ => PluginAndTarget, } } + + pub fn is_target(&self) -> bool { + match *self { + Target | PluginAndTarget => true, + Plugin => false + } + } + + pub fn is_plugin(&self) -> bool { + match *self { + Plugin | PluginAndTarget => true, + Target => false + } + } } diff --git a/src/cargo/ops/cargo_rustc/fingerprint.rs b/src/cargo/ops/cargo_rustc/fingerprint.rs index f8c82df7e..6c5f80656 100644 --- a/src/cargo/ops/cargo_rustc/fingerprint.rs +++ b/src/cargo/ops/cargo_rustc/fingerprint.rs @@ -21,8 +21,9 @@ use super::context::Context; /// The third part of the tuple is a job to run when a package is discovered to /// be fresh to ensure that all of its artifacts are moved to the correct /// location. -pub fn prepare(cx: &mut Context, pkg: &Package, - targets: &[&Target]) -> CargoResult<(Freshness, Job, Job)> { +pub fn prepare<'a, 'b>(cx: &mut Context<'a, 'b>, pkg: &'a Package, + targets: &[&'a Target]) + -> CargoResult<(Freshness, Job, Job)> { let filename = format!(".{}.{}.fingerprint", pkg.get_name(), short_hash(pkg.get_package_id())); let filename = filename.as_slice(); @@ -57,11 +58,20 @@ pub fn prepare(cx: &mut Context, pkg: &Package, for &target in targets.iter() { if target.get_profile().is_doc() { continue } - let layout = cx.layout(target.get_profile().is_plugin()); + let target_layout = cx.layout(false); + let plugin_layout = cx.layout(true); + let req = cx.get_requirement(pkg, target); + for filename in cx.target_filenames(target).iter() { let filename = filename.as_slice(); - pairs.push((layout.old_root().join(filename), - layout.root().join(filename))); + if req.is_target() { + pairs.push((target_layout.old_root().join(filename), + target_layout.root().join(filename))); + } + if req.is_plugin() && plugin_layout.root() != target_layout.root() { + pairs.push((plugin_layout.old_root().join(filename), + plugin_layout.root().join(filename))); + } } } let move_old = Job::new(proc() { diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index 7e2fe4d7e..f5c4601c3 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -7,7 +7,7 @@ use std::os; use std::path; use support::{project, execs, basic_bin_manifest}; -use support::{RUNNING, COMPILING}; +use support::{RUNNING, COMPILING, cargo_dir}; use hamcrest::{assert_that, existing_file}; use cargo::util::process; @@ -226,6 +226,9 @@ test!(plugin_to_the_max { let target = alternate(); assert_that(foo.cargo_process("cargo-build").arg("--target").arg(target), execs().with_status(0)); + assert_that(foo.process(cargo_dir().join("cargo-build")) + .arg("--target").arg(target), + execs().with_status(0)); assert_that(&foo.target_bin(target, "foo"), existing_file()); assert_that( -- 2.30.2